package pref.junx.flybird.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import pref.junx.flybird.R;
import pref.junx.flybird.adapter.SimpleAdapter;
import pref.junx.flybird.entity.Event;

/**
 * Created by JunX on 17/5/13.
 */

public class SimpleFragment extends Fragment {

    @BindView(R.id.empty_view)
    LinearLayout empty_view;

    @BindView(R.id.recyclerview)
    RecyclerView recyclerView;

    private SimpleAdapter adapter;

    private DefaultItemAnimator animator;

    private List data = new ArrayList<Event>();

    public static SimpleFragment newInstance() {
        return new SimpleFragment();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ButterKnife.bind(this, view);
        initView(view);
        initWidget(view);
        initData();
    }

    private void initView(View view) {

    }

    private void initWidget(View view) {
        //setHasFixedSize 的作用就是确保尺寸是通过用户输入从而确保RecyclerView的尺寸是一个常数。
        recyclerView.setHasFixedSize(true);
        recyclerView.setItemAnimator(animator);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        adapter = new SimpleAdapter(getActivity(), data);
        recyclerView.setAdapter(adapter);
    }

    private void initData() {
        Event message = new Event();
        message.setEvent_table("毕业答辩");
        message.setEvent_value("非常非常非常重要，带齐材料，衣冠整洁");
        message.setEvent_zone("瑞10");
        message.setEvent_type("14计科1班");
        data.add(message);

        Event message2 = new Event();
        message2.setEvent_table("聚会");
        message2.setEvent_value("非常非常非常重要，带齐材料，衣冠整洁");
        message2.setEvent_zone("校外");
        message2.setEvent_type("上贤软件工作室");
        data.add(message2);


        Event message3 = new Event();
        message3.setEvent_table("拍照");
        message3.setEvent_value("非常非常非常重要，带齐材料，衣冠整洁");
        message3.setEvent_zone("图书馆");

        data.add(message3);
        message3.setEvent_type("");
        Event message4 = new Event();
        message4.setEvent_table("练车");
        message4.setEvent_value("非常非常非常重要，带齐材料，衣冠整洁");
        message4.setEvent_zone("建阳");

        data.add(message4);
        message4.setEvent_type("");
        Event message5 = new Event();
        message5.setEvent_table("毕业会");
        message5.setEvent_value("非常非常非常重要，带齐材料，衣冠整洁");
        message5.setEvent_zone("三姑");
        message5.setEvent_type("创业部");
        data.add(message5);
        Event message6 = new Event();
        message6.setEvent_type("");
        message6.setEvent_table("开班会");
        message6.setEvent_value("非常非常非常重要，带齐材料，衣冠整洁");
        message6.setEvent_zone("瑞10");
        message6.setEvent_type("14计科");
        data.add(message6);
        message6.setEvent_type("");
        Event message7 = new Event();
        message7.setEvent_type("");
        message7.setEvent_table("旅游");
        message7.setEvent_value("非常非常非常重要，带齐材料，衣冠整洁");
        message7.setEvent_zone("建阳");
        message7.setEvent_type("");
        data.add(message7);
        message7.setEvent_type("");
    }

}
